<style>
    .footer-home{display: none}
    .qi{font-size:.3rem!important;
        margin-left: 0 !important;}
</style>
<header>
    <a href="index.php">
        <i class="iconfont icon-xialalan-copy"></i>
    </a>
    <span class="search_icon  iconfont icon-search"></span>
    <form action="index.php">
        <input type="hidden" name="act" value="food">
        <input type="hidden" name="op" value="search">
        <input class="fl search" type="text" placeholder="搜索商户名、或菜名" name="keyword" value="<?php echo $_GET['keyword']; ?>">
    </form>
</header>
<div class="food_item margin_bot">
    <div class="fl">
        <a href="index.php?act=food&type=0">
            <h1>优惠团购</h1>
            <h5>超值套餐等你团</h5>
            <img src="resource/images/food.jpg" >
        </a>
    </div>
    <div class="fl">
        <a href="index.php?act=food&type=1">
            <h1>附近好券</h1>
            <h5>超值优惠等你领</h5>
            <img src="resource/images/food.jpg" >
        </a>
    </div>
</div>
<div class="order-submit">
    <ul class="food_list">
        <?php if($output['food_list'] && is_array($output['food_list'])): ?>
            <?php foreach($output['food_list'] as $key =>$item): ?>
           <li>
            <a class="flex_display" href="index.php?act=food&op=info&fid=<?php echo $item['fd_id']; ?>">
            <div class="food_img"><img src="<?php echo $item['fd_thumb']; ?>" ></div>
            <div class="food_info flex-1">
                <h1 class="p-1"><?php echo $item['fd_title']; ?></h1>
                <h5><?php echo $item['label']; ?></h5>
                <h5 style="position:absolute;bottom: 1.2rem;line-height:.5rem"><?php echo $item['fd_full_addr']; ?></h5>
                <?php if($item['distance']):?><span><i class="connect iconfont icon-weizhi"></i><?php echo $item['distance']; ?></span><?php endif; ?>
                <div class="color_red food_price">￥<?php echo $item['price']; ?><span class="qi">起</span><span class="">已售<b class="color_red"><?php echo $item['sales']; ?></b>件</span></div>
            </div>
            </a>
        </li>
            <?php endforeach; ?>
        <?php endif; ?>
    </ul>
</div>
<!--加载更多-->
<div class="load" style="text-align: center;display: none;">
    <div class="loading" style="text-align: center;">正在加载中....</div>
</div>
<script>
    //ajax加载分页

    var allNum = <?php echo $output['TotalNum']; ?>,
        allPage = <?php echo $output['TotalPage']; ?>,
        curPage = 1;

    var is_scroll = false;
    $(window).scroll(function () {
        is_scroll = true;
        //已经滚动到上面的页面高度
        var scrollTop = $(this).scrollTop();
        //页面高度
        var scrollHeight = $(document).height();
        //浏览器窗口高度
        var windowHeight = $(this).height();
        //此处是滚动条到底部时候触发的事件，在这里写要加载的数据，或者是拉动滚动条的操作
        if (scrollTop + windowHeight == scrollHeight) {
            $('.load').show();
            loadpage();
        }
    });
    //ajax加载数据
    function loadpage() {
        if(!is_scroll){
            return;
        }
        if (curPage < allPage) {
            curPage += 1;
        } else {
            $('.load').text('没有更多内容了').show();
            return;
        }
        $.get(location.href, {isajax:1,curpage:curPage},function(data){
            if(data){
                $(".food_list").append(data);
                $('.load').hide();
            }
        });
    }

</script>

<?php if ($_SESSION['pos']['js'] == false /*&& strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') == false*/): ?>
    <script src="//webapi.amap.com/maps?v=1.4.3&key=e5c438490a60083b210b012342ff9339"></script>
    <script src="//cache.amap.com/lbs/static/es5.min.js"></script>
    <script>
        var mapObj = new AMap.Map('iCenter');
        var  geolocation;
        mapObj.plugin('AMap.Geolocation', function () {
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,//是否使用高精度定位，默认:true
                timeout: 100000,          //超过10秒后停止定位，默认：无穷大
                maximumAge: 10000,           //定位结果缓存0毫秒，默认：0
                convert: true           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
            });

            geolocation.getCurrentPosition();
            mapObj.addControl(geolocation);
            AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
            AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
        });

        //获取经纬度
        function onComplete(data) {
            console.log(data.position.getLng());
            console.log(data.position.getLat());
            var lng = data.position.getLng();//经度
            var lat = data.position.getLat();//纬度
            $.getJSON('index.php?act=location&op=ajax',{lng:lng,lat:lat},function(json){
                /*json.reloads && json.city && popAlert('定位到'+json.city+'，将为您切换到'+json.city, function () {
                 location.reload();
                 }, 0);*/
                json.reloads && json.city && location.reload();
            });
        }
        function onError(data) {
            console.log(data);
            //popAlert('您禁用了定位' + e.message);
        }
    </script>
<?php endif; ?>